package com.kfm.hotel.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class MD5Util {
    //使用MD5静态方法加密-
    public static String MD5(String password,String salStr){
        try {
            //1.创建MessqgeDigest指定MD5算法
            MessageDigest digest01 = MessageDigest.getInstance("MD5");
            //2.加载变量，与输入字符串连接
            byte[] bytes = password.concat(salStr).getBytes();
            //3.更新字节数
            digest01.update(bytes);
            //4.进行加密操作
            byte[] digest02 = digest01.digest();
            //5.将加密后的字节数与盐值进行编码
            String encodeToString = Base64.getEncoder().encodeToString(digest02);
            //6.返回值
            return encodeToString;

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
    //进行测试加密
    public static void main(String[] args) {
        MD5("123456","admin");
        MD5("12345njknhuiy6","admin");
        MD5("1234bhjgyunhhgfhd56","admin");
    }
}